<?php
class UserEntityBase extends EntityBase {
    public $id;
    public $email;
    public $password;
    public $fullname;
    public $birthday;
    public $address;
    public $phone;
    public $userType;
    public $creation_date;
    public $last_login;
    public $balance;
    public $picture;
    public $gender;
    public $status;

    const INACTIVE = 0;
    const ACTIVE = 1;
    const SUSPENDED = 2;
    const BLOCKED = 3;
    public function __construct($arrValue = null, $prefix = '') {
        if(!is_null($arrValue) && is_array($arrValue)) {
            $this->id = (int) ($arrValue[$prefix . 'id']);
            $this->email = strval ($arrValue[$prefix . 'email']);
            $this->password = strval ($arrValue[$prefix . 'password']);
            $this->fullname = strval ($arrValue[$prefix . 'fullname']);
            $this->birthday = strval ($arrValue[$prefix . 'birthday']);
            $this->address = strval ($arrValue[$prefix . 'address']);
            $this->phone = strval ($arrValue[$prefix . 'phone']);
            $this->userType = strval ($arrValue[$prefix . 'userType']);
            $this->creation_date = strval ($arrValue[$prefix . 'creation_date']);
            $this->last_login = strval ($arrValue[$prefix . 'last_login']);
            $this->balance = strval ($arrValue[$prefix . 'balance']);
            $this->picture = strval ($arrValue[$prefix . 'picture']);
            $this->gender = strval ($arrValue[$prefix . 'gender']);
            $this->status = strval ($arrValue[$prefix . 'status']);
        }
    }

    /**
     * Check the role of the user whether his role is Admin or not
     *
     * @return bool true if user is ADMIN else false
     */
    public function isAdministrator($status = self::ACTIVE) {
        if (is_null($this->userType)) {
            return false;
        }

//        if($this->userType == ROLE_ADMIN || $this->userType == ROLE_ADMIN_SUPER) {
//            return true;
//        }
return true;

        return false;
    }




    /**
     * Check the role of the user whether his role is Member (Independent customer) or not
     *
     * @return bool true if user is Member (Independent customer) else false
     */
    public function isMember($status = self::ACTIVE) {
        if (is_null($this->userType)) {
            return false;
        }

        if($this->userType == ROLE_MEMBER) {
            return true;
        }

        return false;
    }


    /**
     * Get status name of user
     *
     * @access public
     *
     * @return string name of status
     *
     */
    public function getStatusName() {
        $arrStatusList = self::getStatusList();
        return isset($arrStatusList["{$this->status}"]) ? $arrStatusList["{$this->status}"] : '';
    }

    /**
     * Get type name of user
     *
     * @access public
     *
     * @return string name of type of user
     *
     */
    public function getUserTypeName() {
        $arrUserTypeList = self::getUserTypeList();
        return isset($arrUserTypeList["{$this->userType}"]) ? $arrUserTypeList["{$this->userType}"] : '';
    }

    /**
     * Get list of user status
     *
     * @access public
     *
     * @return array of user status
     *
     */
    public static function getStatusList() {
        return array(self::INACTIVE	=> 'INACTIVE',
                self::ACTIVE 	=>'ACTIVE',
                self::SUSPENDED =>'SUSPENDED',
                self::BLOCKED  	=>'BLOCKED'
        );
    }

    /**
     * Get Verified Status
     *
     * @access public
     *
     * @return array of user status
     *
     */
    public static function getVerifyStatusList() {
        return array(self::INACTIVE	=> 'NOT VERIFIED',
                self::ACTIVE 	=> 'VERIFIED'
        );
    }

    public function getVerifyStatusName() {
        $arrVerifyStatusList = self::getVerifyStatusList();
        return isset($arrVerifyStatusList["{$this->hasVerified}"]) ? $arrVerifyStatusList["{$this->hasVerified}"] : '';
    }

    /**
     * Get all customer types
     *
     * @return array of customer type
     */
    public static function getCustomerTypeList() {
        return array(ROLE_MEMBER => 'MEMBER');
    }

    /**
     * Get ADMIN and Supervisor types of user
     *
     * @return array of ADMIN and supervisor types
     */
    public static function getAdminTypeList() {
        return array(ROLE_ADMIN => 'ADMIN',
                ROLE_ADMIN_SUPER => 'ADMIN_SUPER'
        );
    }

    /**
     * Get all types of user
     *
     * @return array of user type
     */
    public static function getUserTypeList() {
        return array(ROLE_ADMIN 	=> 'ADMIN',
                ROLE_ADMIN_SUPER 	=> 'ADMIN_SUPER',
                ROLE_MEMBER 	=> 'Thành viên',
                ROLE_SHIPPING => 'Giao hàng',
                ROLE_ACCOUNTANT => 'Kế toán',
                ROLE_DEALMANAGER => 'Quản lý deal',
                ROLE_SUPPORT => 'Hỗ trợ khách hàng'
                );
    }
	
   	
    /**
     * Get all types of user
     *
     * @return array of user type
     */
    public static function getAllUserTypeList() {
        return array(ROLE_ADMIN_SUPER 	=> 'ADMIN',
                ROLE_DEALMANAGER 	=> 'Quản lý deal',
                ROLE_ACCOUNTANT 	=> 'Kế toán',
                ROLE_SHIPPING => 'Giao hàng',
                ROLE_SUPPORT => 'Hỗ trợ khách hàng',
                ROLE_MEMBER => 'Khách hàng'
                );
    }
	 
    
    /**
     * Get MEMBER types of user
     *
     * @return array of user type
     */
    public static function getMemberUserTypeList() {
        return array(
                ROLE_MEMBER 	=> 'MEMBER');
    }

    /**
     * Get all normal admin types
     *
     * @return array of customer type
     */
    public static function getNormalAdminTypeList() {
        return array(ROLE_ADMIN => 'ADMIN');
    }

    /**
     * Get all fields for selecting columns
     *
     * @param string $alias: alias of table
     * @param string $prefix
     * @return string
     */
    public static function getSelectColumns($alias, $prefix = '') {
        $arrValue = array(
                "{$alias}.id AS `{$prefix}id`",
                "{$alias}.email AS `{$prefix}email`",
                "{$alias}.password AS `{$prefix}password`",
                "{$alias}.fullname AS `{$prefix}fullname`",
                "{$alias}.birthday AS `{$prefix}birthday`",
                "{$alias}.address AS `{$prefix}address`",
                "{$alias}.phone AS `{$prefix}phone`",
                "{$alias}.userType AS `{$prefix}userType`",
                "{$alias}.creation_date AS `{$prefix}creation_date`",
                "{$alias}.last_login AS `{$prefix}last_login`",
                "{$alias}.balance AS `{$prefix}balance`",
                "{$alias}.picture AS `{$prefix}picture`",
                "{$alias}.gender AS `{$prefix}gender`",
                "{$alias}.status AS `{$prefix}status`",
        );

        return implode(',', $arrValue);
    }
}